package com.jingdun.sport.api.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jingdun.sport.bean.model.Dict;
import com.jingdun.sport.common.bean.Qiniu;
import com.jingdun.sport.service.DictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class QiniuPutPolicyController {

    @Autowired
    private DictService dictService;

    @Autowired
    private Qiniu qiniu;

    // 更新七牛云的策略
    @GetMapping(value = "/updateQiniuPutPolicy")
    public String updateQiniuPutPolicy() {
        QueryWrapper<Dict> dictQueryWrapper = new QueryWrapper<>();
        dictQueryWrapper.eq("name", "qiniu_policy");
        try {
            Dict dict = dictService.getOne(dictQueryWrapper);
            if (dict != null) {
                qiniu.setPolicyStr(dict.getValue());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "ok";
    }
}
